home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / NeoIntroTCL3.0 folder / TCL / NeoDemo / Source / CNeoDialogText.cp < prev    next >
Encoding:
Text File  |  1994-08-01  |  4.7 KB  |  163 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CNeoDialogText.c
  3.  
  4.         Subclass of CEditText that implements text items in dialogs.
  5.         NeoDialogText items have a border, pass the special keys tab, enter,
  6.         return, and escape to their supervisors, and can be validated.
  7.  
  8.     SUPERCLASS = CDialogText
  9.  
  10.     Copyright © 1991 Symantec Corporation.    All rights reserved.
  11.     Copyright © 1992 NeoLogic Systems        All rights reserved.
  12.  
  13.  
  14.  ******************************************************************************/
  15.  
  16. #include "NeoTypes.h"
  17. #include <Packages.h>
  18. // #include <Quickdraw.h>
  19. #include "Commands.h"
  20. #include "CPaneBorder.h"
  21. #include "CNeoDialogText.h"
  22. #include "CNeoDLOGDialog.h"
  23. #include "CNeoDemoDoc.h"
  24.  
  25. #define kBorderAmount    2    /* white space between border and text of edit field */
  26.  
  27. extern CBureaucrat *gGopher;        /* First in line to get commands    */
  28.  
  29. /******************************************************************************
  30.  INeoDialogText
  31.  
  32.      Initialize a NeoDialogText object. It is initialized to not required,
  33.      no maximum length, and not stylable.  Use the SetConstraints and Specify
  34.      methods to modify these characteristics.
  35.  
  36. ******************************************************************************/
  37.  
  38. void CNeoDialogText::INeoDialogText(CView *anEnclosure, CView *aSupervisor,
  39.                 short aWidth, short aHeight,
  40.                 short aHEncl, short aVEncl,
  41.                 SizingOption aHSizing, SizingOption aVSizing,
  42.                 short aLineWidth, Boolean aBorderVisible)
  43. {
  44.     fBorderVisible = aBorderVisible;
  45.  
  46.     CDialogText::IDialogText(anEnclosure, aSupervisor,
  47.         aWidth, aHeight, aHEncl, aVEncl,
  48.         aHSizing, aVSizing, aLineWidth);
  49.  
  50. }    /* CNeoDialogText::INeoDialogText */
  51.  
  52. /******************************************************************************
  53.  MakeBorder
  54.  
  55.      Make a PaneBorder object for the NeoDialogText. Override to change
  56.      the border appearance.
  57. ******************************************************************************/
  58.  
  59. void CNeoDialogText::MakeBorder(void)
  60. {
  61.     Rect    margin;
  62.     CPaneBorder *border;
  63.  
  64.     border = new(CPaneBorder);
  65.     border->IPaneBorder(kBorderFrame);
  66.     border->SetPattern(fBorderVisible ? &qd.black : &qd.white);
  67.     SetRect(&margin, -kBorderAmount, -kBorderAmount, kBorderAmount, kBorderAmount);
  68.     border->SetMargin(&margin);
  69.     SetBorder(border);
  70.  
  71. }    /* CNeoDialogText::MakeBorder */
  72.  
  73. void CNeoDialogText::showBorder(const Boolean aShow)
  74. {
  75.     if (aShow != fBorderVisible) {
  76.         if (aShow)
  77.             itsBorder->SetPattern(&qd.black);
  78.         else
  79.             itsBorder->SetPattern(&qd.white);
  80.         RefreshBorder();
  81.     }
  82.     fBorderVisible = aShow;
  83. }
  84.  
  85. /******************************************************************************
  86.  DoClick {OVERRIDE}
  87.  
  88.         Respond to a mouse click within the EditText
  89.  ******************************************************************************/
  90.  
  91. void    CNeoDialogText::DoClick(
  92.     Point        hitPt,                    /* Mouse location in Frame coords    */
  93.     short        modifierKeys,            /* State of modifier keys            */
  94.     long        when)                    /* Tick time of mouse click            */
  95. {
  96.     Boolean        param    = TRUE;
  97.  
  98.     inherited::DoClick(hitPt, modifierKeys, when);
  99.  
  100.     if (!fBorderVisible)
  101.         BroadcastChange(NeoDialogBordersChanged, (void *)¶m);
  102. }
  103.  
  104. /* if pasting & there is a PICT in the scrap - act as if the file picture item
  105.    is selected. i.e., make a new image object & put the picture into it.
  106. */
  107. void    CNeoDialogText::DoCommand(long    theCommand)
  108. {
  109.     CNeoDemoDoc *    document;
  110.  
  111.     if(theCommand == cmdPaste) {
  112.         document = ((CNeoDemoDoc *)((CNeoDLOGDialog *)itsSupervisor)->itsSupervisor);
  113.         if(!document->doPaste())            /* return of zero means there was an image in the scrap */
  114.             return;
  115.     }
  116.  
  117.     inherited::DoCommand(theCommand);        /* pass it on */
  118. }
  119.  
  120. /******************************************************************************
  121.  DoKeyDown {OVERRIDE}
  122.  
  123.      Handle keypresses in a DialogText object. Keys that have a special meaning
  124.      in a dialog (tab, return, enter, and Escape) are passed to itsSupervisor,
  125.      all other keys are passed through to the superclass.
  126. ******************************************************************************/
  127.  
  128. void CNeoDialogText::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
  129. {
  130.     CNeoDemoDoc *    document;
  131.  
  132.     if ((theChar >= 0x08 &&
  133.          theChar < 0x14) ||
  134.         (theChar >= 0x20 &&
  135.          theChar < 0xFF)) {
  136.         document = ((CNeoDemoDoc *)((CNeoDLOGDialog *)itsSupervisor)->itsSupervisor);
  137.         gNeoDatabase = (CNeoDatabase *)document->itsFile;
  138.         document->setImageDirty(this, &theChar, FALSE);
  139.     }
  140.  
  141. //    switch (theChar)
  142. //    {
  143. //        case '\t':
  144. //            BroadcastChange(NeoDialogBordersChanged, (void *)TRUE);
  145.             /* FALL THROUGH */
  146.  
  147. //        default:
  148.     inherited::DoKeyDown(theChar, keyCode, macEvent);
  149. //    }
  150.  
  151. }    /* CNeoDialogText::DoKeyDown */
  152.  
  153. Boolean CNeoDialogText::BecomeGopher(Boolean fBecoming)
  154. {
  155.     if (fBecoming)
  156.         Activate();
  157.     else
  158.         Deactivate();
  159.  
  160.     return inherited::BecomeGopher(fBecoming);
  161. }
  162.  
  163.